package com.jf.util;

public class ResultJson {

    private static final Integer SUCCESS_CODE=200;
    private static final Integer ERROR_CODE=500;
    private static final String SUCCESS_MSG="success";
    private static final String ERROR_MSG="服务器异常，请稍后再试";


    private Integer code;
    private String msg;
    private Object data;


    public static ResultJson success(String msg){
        ResultJson resultJson = new ResultJson();
        resultJson.setCode(SUCCESS_CODE);
        resultJson.setMsg(msg);
        return resultJson;
    }

    public static ResultJson success(){
        return success(SUCCESS_MSG);
    }

    public static ResultJson success(Object data){
        ResultJson resultJson = new ResultJson();
        resultJson.setCode(SUCCESS_CODE);
        resultJson.setMsg(SUCCESS_MSG);
        resultJson.setData(data);
        return resultJson;
    }

    public static ResultJson error(Integer code,String msg){
        ResultJson resultJson = new ResultJson();
        resultJson.setCode(code);
        resultJson.setMsg(msg);
        return resultJson;
    }

    public static ResultJson error(Integer code){
        return error(code,ERROR_MSG);
    }

    public static ResultJson error(String msg){
        return error(ERROR_CODE,msg);
    }




    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultJson{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
